<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>返回两个日期之间相差的天数</title>
</head>

<body>
  <script>
    var date1 = new Date("2023-04-05");
    var date2 = new Date("2022-04-05");
    var a = date1 - date2 //毫秒数
    console.log(a / 86400000);
  </script>
</body>

</html>